package database

import (
	"database/sql"
	_ "github.com/go-sql-driver/mysql"
	"log"
	"goapp/config"
)

var db *sql.DB

func InitMysql() {
	var err error
	db, err = sql.Open("mysql", config.MYSQL_USERNAME+":"+config.MYSQL_PASSWORD+"@tcp("+config.MYSQL_HOSTNAME+":"+config.MYSQL_HOSTPORT+")/"+config.MYSQL_BASE+"?charset="+config.MYSQL_CHARSET)

	//defer db.Close()

	if err != nil {
		log.Fatal(err.Error())
	}


	db.SetMaxIdleConns(20)
	db.SetMaxOpenConns(20)

	err = db.Ping()
	if err != nil {
		log.Fatal(err.Error())
	}
}

func GetDb()(*sql.DB)  {
	return db
}

